#!/bin/bash
########################################
#  This file is part of the open-eBackup project.
# Copyright (c) 2024 Huawei Technologies Co.,Ltd.
#
# open-eBackup is licensed under MPL v2.
# You can use this software according to the terms and conditions of the MPL v2.
# You may obtain a copy of MPL v2 at:
#
#          https://www.mozilla.org/en-US/MPL/2.0
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the MPL v2 for more details.
########################################

set -eux
set -o pipefail

install_dir=$1

# check install files
ls make-4.3-4.oe2203sp3.src.rpm

# clear
[ -d "${install_dir}" ] && rm -rf ${install_dir}
mkdir -p ${install_dir}

# install
cp make-4.3-4.oe2203sp3.src.rpm ${install_dir}
cd ${install_dir}
rpm -ivh make-4.3-4.oe2203sp3.src.rpm

cd /root/rpmbuild/SOURCES/
tar -zxvf make-4.3.tar.gz
cd make-4.3

#开始编译
tmp_cpus=$(grep -w processor /proc/cpuinfo|wc -l)
./configure --prefix=${install_dir}
make -j ${tmp_cpus}
make install

#link
ln -sf ${install_dir}/bin/make ${install_dir}/bin/gmake
ln -sf ${install_dir}/bin/* /usr/local/bin

echo "Successfully installed the tool make 4.3"
